#include "str_array.h"

static int
bf(const byte * hs, size_t hs_len, const byte * nd, size_t nd_len)
{
	if (hs_len < nd_len) {
		return -1;
	}

	size_t i = 0;
	size_t j = 0;
	const byte * p = 0;
	for (i = 0, p = hs; i <= hs_len - nd_len; ++i, ++p) {
		for (j = 0; j < nd_len && p[j] == nd[j]; ++j) {}
		if (j == nd_len) {
			return i;
		}
	}

	return -1;
}

int
sq_str_bf(const sq_str * haystack, const sq_str * needle)
{
	return bf(haystack->data, haystack->len, needle->data, needle->len);
}

